package com.ikun.mapper;

import com.ikun.pojo.TbUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface TbUserMapper {

    //查询好人榜的方法
    public List<TbUser> selGoodman(@Param("date") int date);
    //查询所有用户的方法
    public List<TbUser> showusers();
    //删除用户的方法
    public int deluser(@Param("id") int id);

    //修改用户头像
    @Update("update tb_user set pic = #{url} where id = #{id}")
    public int updateMyPic(@Param("id") Long userid,@Param("url") String url);

    //修改用户密码
    @Update("update tb_user set pwd = #{newPwd} where id = #{id} and pwd = #{oldPwd}")
    public int updateMyPwd(@Param("id") Long userid,@Param("oldPwd") String oldPwd,@Param("newPwd") String newPwd);

    //修改用户信息
    @Update("update tb_user set nickname = #{u.nickname},realname = #{u.realname},sex = #{u.sex},email = #{u.email},phone = #{u.phone},department = #{u.department},profession = #{u.profession},classes = #{u.classes} where id = #{u.id}")
    public int updateMyInfo(@Param("u")TbUser tbUser);

    //给用户加余额
    @Update("update tb_user set balance = balance+#{balance1} where id = #{id}")
    public int addRechargeByUid(@Param("id") Long userid,@Param("balance1") BigDecimal balance);

    //给用户扣余额
    @Update("update tb_user set balance = balance-#{balance1} where id = #{id} and balance>=#{balance1}")
    public int deductMoney(@Param("id") Long userid,@Param("balance1") BigDecimal balance);

    //查询一个用户的方法
    public TbUser getUser(@Param("account")String account,@Param("pwd")String pwd);

    //注册一个用户的方法
    @Insert("INSERT into tb_user (nickname,account,pwd,email,sex)" +
            " VALUES (#{nickname},#{account},#{pwd},#{email},#{sex})")
    public int registerUser(@Param("userid") String  userid,
                            @Param("account") String  account,
                            @Param("pwd") String  pwd,
                            @Param("email") String  email,
                            @Param("sex") String  sex);
    //修改用户信息（管理端）
    @Update("update tb_user set nickname =#{nickname},realname =#{realname},pwd =#{pwd},sex =#{sex},email =#{email},phone =#{phone},department =#{department},profession =#{profession},classes =#{classes} where id = #{id}")
    public int updatemsg(@Param("id") int id,@Param("nickname") String nickname,@Param("realname") String realname,@Param("pwd") String pwd,@Param("sex") String sex,@Param("email") String email,@Param("phone") String phone,@Param("department") String department,@Param("profession") String profession,@Param("classes") String classes);
}